﻿using ErrorOr;
using Gym.Application.Common.Interfaces;
using Gym.Domain.SubscriptionAggregate;
using MediatR;

namespace Gym.Application.Subscriptions.Queries.ListSubscriptions
{
    public class ListSubscriptionsQueryHandler : IRequestHandler<ListSubscriptionsQuery, ErrorOr<List<Subscription>>>
    {
        private readonly ISubscriptionsRepository _subscriptionRepository;
        public ListSubscriptionsQueryHandler(ISubscriptionsRepository subscriptionRepository)
        {
            _subscriptionRepository = subscriptionRepository;
        }
        public async Task<ErrorOr<List<Subscription>>> Handle(ListSubscriptionsQuery request, CancellationToken cancellationToken)
        {
            return await _subscriptionRepository.ListAsync();
        }
    }
}
